package com.chenyi.data.structure.linked;

import javax.xml.ws.soap.Addressing;
import java.security.Signature;

/**
 * @author by chenyi
 * @className TestLinked
 * @date 2021/12/21 14:52
 */

public class TestLinked {
    public static final int SIZE = 10;
    public static void main(String[] args) {
        circularLinkedTest();
    }

    public static void circularLinkedTest() {
        CircularLinkedList circularLinkedList = new CircularLinkedList();
        for (int i = 0; i < SIZE; i++) {
            circularLinkedList.add(i);
        }
        circularLinkedList.showLinked();
    }

    public static void singleLinkedTest() {
        SingleLinkedList singleLinkedList = new SingleLinkedList();
        for (int i = 0; i < SIZE; i++) {
            singleLinkedList.add(i);
        }
        singleLinkedList.showLinked();

        System.out.println("===================");
        singleLinkedList.remove(0);
        singleLinkedList.showLinked();

        System.out.println("=====================");
        singleLinkedList.remove(4);
        singleLinkedList.showLinked();

        System.out.println("===================");
        singleLinkedList.update(5, 4);
        singleLinkedList.showLinked();

        System.out.println("===================");
        singleLinkedList.remove(7);
        singleLinkedList.showLinked();

        System.out.println("======================");
        singleLinkedList.add(10, 6);
        singleLinkedList.showLinked();

        System.out.println("=====================");
        System.out.println(singleLinkedList.getLastLinkedByIndex(3));

        System.out.println("====================");
        singleLinkedList.reversalLinked();
        singleLinkedList.showLinked();
    }

    public static void linkedTest() {
        LinkedList linkedList = new LinkedList();
        for (int i = 0; i < SIZE; i++) {
            linkedList.add(i);
        }
        linkedList.showLinked();

        System.out.println("==================");
        linkedList.add(1, 5);
        linkedList.add(1, 0);
        linkedList.add(1, linkedList.getSize() - 1);
        linkedList.showLinked();

        System.out.println("=====================");
        linkedList.update(10, 0);
        linkedList.update(100, linkedList.getSize() - 1);
        linkedList.update(11, 5);
        linkedList.showLinked();

        System.out.println("===================");
        linkedList.remove(linkedList.getSize() - 1);
        linkedList.remove(0);
        linkedList.remove(4);
        linkedList.showLinked();

    }
}
